package com.hoshiicloud.goods.controller;

import com.hoshiicloud.common.rpc.Response;
import com.hoshiicloud.goods.entity.goods.GoodsCategorySpec;
import com.hoshiicloud.goods.entity.goods.GoodsSpecifications;
import com.hoshiicloud.goods.service.GoodsCategorySpecService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.collections.CollectionUtils;
import org.hibernate.validator.constraints.ParameterScriptAssert;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 类目规格
 * @author linjx on 2019/7/25
 */
@RestController
@RequestMapping("/goods/goods-category-spec")
@Api(value = "类目关联规格",tags = {"类目关联规格"})
public class GoodsCategorySpecController {
    @Autowired
    private GoodsCategorySpecService goodsCategorySpecService;

    @ApiOperation(value = "新增类目关联规格信息,多条")
    @PostMapping("/saveBatch")
    public Response<Boolean> saveBatch(@RequestBody List<GoodsCategorySpec> list){
        if(CollectionUtils.isEmpty(list)){
            return Response.data(true);
        }
        return Response.data(goodsCategorySpecService.saveBatch1(list));

    }

    @DeleteMapping("/deleteByCategoryId/{categoryId}")
    public Response<Integer> deleteByCategoryId(@PathVariable("categoryId") Long categoryId){
        return Response.data(goodsCategorySpecService.deleteByCategoryId(categoryId));
    }

    @ApiOperation("查询商品类目下关联的属性信息")
    @GetMapping("/listByCategoryId/{categoryId}")
    public Response<List<GoodsSpecifications>> listByCategoryId(@PathVariable("categoryId") Long categoryId){
        return Response.data(goodsCategorySpecService.listByCategoryId(categoryId));
    }

    @GetMapping("/getProperSpecByCategoryId")
    public Response getProperSpecByCategoryId(@RequestParam String categoryId) {
        return Response.data("");
    }

}
